<?php

/**
 * Classe pour une tache cron  : supprimer les anciennes photos
 */
class crondeleteoldphotosCtrl extends jControllerCmdLine {
    
    function index() {
        if ( array_key_exists('REMOTE_ADDR', $_SERVER) )
            die("Can only be run from the command line!");
        $rep = $this->getResponse("cmdline"); // cmdline response by default
        jClasses::inc('commun~communSrv');
        
        communSrv::deleteOldPhotos();
               
        // enregistrement des traces dans le fichier log
        $logDir  = 'logs/';
        $logFile = $logDir . 'deleteoldphotos.log';
        $fp      = fopen($logFile,"a+");
        $stdin   = fopen("php://stdin", "r");

        // Use unbuffered output
        ob_implicit_flush (true);

        while ($line = fgets($stdin)){
           fwrite($fp, $line);
        }

        fclose($fd);
        fclose($stdin);
        
        echo 'OK - old pictures deleted at ' . date("Y-m-d h:i:s");
        return $rep;
    }
    
    
}
?>
